package com.hmall.item.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    /**
     * 扣减库存
     *
     * @param itemId
     * @param num
     */
    @Override
    public void decreaseStock(Long itemId, Integer num) {
        update().setSql("stock=stock-"+num).eq("id", itemId).update();

    }

    /**
     * 恢复库存
     *
     * @param itemId
     * @param num
     */
    @Override
    public void addStock(Long itemId, Integer num) {
        update().setSql("stock=stock+"+num).eq("id", itemId).update();

    }
}
